
#!usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@author:MCC
@file: myPlayBlast
@time: 2018/11/22 19:04
"""
import os
import maya.cmds as cmds

def getFrameRange():
	startTime = cmds.playbackOptions(q = True,min = True)
	endTime = cmds.playbackOptions(q = True,max = True)
	return [int(startTime),int(endTime)]



def RunExport(path, publishPath=''):
	cmds.file(path, o=1, f=1)
	print(publishPath)
	print("wwwwwwwwwwwwwwwwwwwwww")

	print(path)
	unknownNodeList = cmds.ls(type="unknown")
	if unknownNodeList:
		cmds.lockNode(unknownNodeList,l=0 )
		cmds.delete (unknownNodeList)
		
	unknownDagList = cmds.ls(type="unknownDag")
	if unknownDagList:
		cmds.delete (unknownDagList)   
		
	loaded_plugins = cmds.unknownPlugin(query=True, list=True)
	if loaded_plugins:
		for plugin in loaded_plugins:
			cmds.unknownPlugin(plugin, remove=True)

	# cmds.loadPlugin("animImportExport")
	#
	videosPath = os.path.dirname(path)
	videosName = os.path.basename(path).split(".")[0]
	# name = os.path.basename(path).split(".")[0]
	# geoList = getObject()
	# nurbsCurvesList=selectNurbsCurve()
	# print "+++++++++++++++",geoList
	# bakeAnimation(nurbsCurvesList,frameRange[0],frameRange[1])
	# cmds.select(geoList[0])
	# fileDirs = abcPath+"/%s" % name
	# exportAnmiCurve("%s.anim"%fileDirs)

	all_camera = [ i for i in cmds.listCameras ( p = 1 ) if i != 'persp' ]
	obj_list = [ ]
	playblastCame = ''
	for i in all_camera :
		if not cmds.referenceQuery ( i , isNodeReferenced = True ) :
			obj_list.append ( i )
			playblastCame = obj_list [ 0 ]
	CameraShape = cmds.listRelatives ( playblastCame , shapes = 1 ) [ 0 ]
	cmds.setAttr ( playblastCame + '.rnd' , 1 )
	cmds.setAttr ( 'hardwareRenderingGlobals.gammaValue ' , 1 )
	cmds.setAttr('hardwareRenderingGlobals.enableTextureMaxRes', 1)
	cmds.setAttr('hardwareRenderingGlobals.textureMaxResolution', 256)
	movPath = "%s/%s.mov"%(videosPath,videosName)
	cmds.playblast(filename=movPath, format="qt", sequenceTime=0, clearCache=1,    viewer=0,   showOrnaments=1,  fp=4,  fo=1, percent=100, compression="H.264", quality=100, widthHeight=[1080, 720])


